package org.example;

public class Test1 {
    //没写出来
    public String intToRoman2(int num) {
        StringBuilder sb = new StringBuilder();
        int[] hash1 = new int[7];
        hash1[0] = 1000;
        hash1[1] = 500;
        hash1[2] = 100;
        hash1[3] = 50;
        hash1[4] = 10;
        hash1[5] = 5;
        hash1[6] = 1;
        char[] hash2 = new char[7];
        hash2[0] = 'M';
        hash2[1] = 'D';
        hash2[2] = 'C';
        hash2[3] = 'L';
        hash2[4] = 'X';
        hash2[5] = 'V';
        hash2[6] = 'I';
        int index = 0;
        while (num > 0) {
            int tmp = num/(index <= 1 ? 100 : 10);
            if (tmp == 4 || tmp == 9 && index != 0) {
                if (tmp == 4) {
                    sb.append(hash2[index+1]);
                    sb.append(hash2[index]);
                    num %= hash1[index+1];
                }else {
                    sb.append(hash2[index-1]);
                    sb.append(hash2[index]);
                }
            }else {
                for (int i = 0; i < num/hash1[index]; i++) {
                    sb.append(hash2[index]);
                }
                num %= hash1[index];
            }
            index++;
        }
        return sb.toString();
    }

    //正解
    int[] values = {1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1};
    String[] symbols = {"M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"};

    public String intToRoman(int num) {
        StringBuffer roman = new StringBuffer();
        for (int i = 0; i < values.length; ++i) {
            int value = values[i];
            String symbol = symbols[i];
            while (num >= value) {
                num -= value;
                roman.append(symbol);
            }
            if (num == 0) {
                break;
            }
        }
        return roman.toString();
    }

    public static void main(String[] args) {
        Test1 test1 = new Test1();
        test1.intToRoman(3749);
        System.out.println(777);
        StringBuilder sb = new StringBuilder();
    }
}
